#!/bin/bash

# Memento Dictionary Service API 测试脚本

BASE_URL="http://localhost:8080"

echo "=== Memento Dictionary Service API 测试 ==="
echo ""

# 1. 健康检查
echo "1. 健康检查"
curl -s "$BASE_URL/api/dictionary/health" | jq .
echo ""

# 2. 获取词典源配置
echo "2. 获取词典源配置"
curl -s "$BASE_URL/api/sources" | jq .
echo ""

# 3. 获取启用的词典源
echo "3. 获取启用的词典源"
curl -s "$BASE_URL/api/sources/enabled" | jq .
echo ""

# 4. 获取词典源统计
echo "4. 获取词典源统计"
curl -s "$BASE_URL/api/sources/stats" | jq .
echo ""

# 5. 检查下载状态
echo "5. 检查CEDICT下载状态"
curl -s "$BASE_URL/api/dictionary/download/status/CEDICT" | jq .
echo ""

# 6. 获取已下载文件
echo "6. 获取已下载文件"
curl -s "$BASE_URL/api/dictionary/download/files" | jq .
echo ""

# 7. 获取下载任务
echo "7. 获取下载任务"
curl -s "$BASE_URL/api/dictionary/download/tasks" | jq .
echo ""

# 8. 获取词典统计
echo "8. 获取词典统计"
curl -s "$BASE_URL/api/dictionary/stats" | jq .
echo ""

# 9. 搜索单词（如果已有数据）
echo "9. 搜索单词 'hello'"
curl -s "$BASE_URL/api/dictionary/search?word=hello" | jq .
echo ""

# 10. 模糊搜索
echo "10. 模糊搜索 'hel'"
curl -s "$BASE_URL/api/dictionary/search/fuzzy?keyword=hel" | jq .
echo ""

echo "=== 测试完成 ==="
echo ""
echo "如果需要加载词典数据，请运行："
echo "curl -X POST $BASE_URL/api/dictionary/load"
echo ""
echo "如果需要下载特定词典源，请运行："
echo "curl -X POST $BASE_URL/api/sources/CEDICT/download"
